﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Reflection; 
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HF.BizWinner.DB;
using HF.BizWinner.DB.Linq;

public partial class CI : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BizWinnerDataContext bdc = new BizWinnerDataContext();
        var cis = (from ci in bdc.CI
                  select ci).Skip(10).Take(20);

        Repeater6.DataSource = ToDataTable((IEnumerable)cis);
        Repeater6.DataBind();
    }

    /// <summary>    
    /// 將 IEnumerable 轉換至 DataTable    
    /// </summary>    
    /// <param name="list">IEnumerable</param>    
    /// <returns>DataTable</returns>    
    public DataTable ToDataTable(IEnumerable list)  
    {  
        DataTable dt = new DataTable();  
        bool schemaIsBuild = false;  
        PropertyInfo[] props = null;  
  
        foreach (object item in list)  
        {  
            if (!schemaIsBuild)  
            {  
                props = item.GetType().GetProperties();  
                foreach (var pi in props)  
                {  
                    dt.Columns.Add(new DataColumn(pi.Name, pi.PropertyType));  
                }  
  
                schemaIsBuild = true;  
            }  
  
            var row = dt.NewRow();  
            foreach (var pi in props)  
            {  
                row[pi.Name] = pi.GetValue(item, null);  
            }  
  
            dt.Rows.Add(row);  
        }  
  
        dt.AcceptChanges();  
        return dt;  
    }  
}
